#version 120
uniform sampler2D u_FBTexture;
uniform int u_GuassDir;
uniform vec2 u_Reslution;
uniform vec3 u_Color;
varying vec2 v_TexCoord;

#define PIXELS 16

float NGuass(float x) {
    const float a = 0.3989422804014327;
    return a * exp(pow(x, 2.0) / -2.0);
}

float Guass(float sigma, float x) {
    x = x / sigma;
    return NGuass(x) / sigma;
}

void main() { 
    // gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); 
    const float radius1 = 1.2;
    const float radius0 = 20.0;
    const float K_r0 = 0.4;
    float weight = Guass(radius0, (float(0))) * K_r0 + Guass(radius1, (float(0)));
    float intgeral = texture2D(u_FBTexture, v_TexCoord).x * weight;

    if(u_GuassDir == 0) {
        for(int i = 1; i <= PIXELS; i++) {
            vec2 offset = vec2(float(i) / u_Reslution.x, 0.0);
            weight = Guass(radius0, (float(i))) * K_r0 + Guass(radius1, (float(i)));
            intgeral += texture2D(u_FBTexture, v_TexCoord + offset).x * weight;
            intgeral += texture2D(u_FBTexture, v_TexCoord - offset).x * weight;
        }
    } else {
        for(int i = 1; i <= PIXELS; i++) {
            vec2 offset = vec2(0.0, float(i) / u_Reslution.y);
            weight = Guass(radius0, (float(i))) * K_r0 + Guass(radius1, (float(i)));
            intgeral += texture2D(u_FBTexture, v_TexCoord + offset).x * weight;
            intgeral += texture2D(u_FBTexture, v_TexCoord - offset).x * weight;
        }
    }
    // vec3(0.3, 0.6, 1.0)
    float k = pow(intgeral * 4, 1);
    gl_FragColor = vec4(vec3(k * vec3(0.5, 1.0, 0.6)), 1.0); 
}
